<%@page import="java.util.ArrayList" %>
<%@page import="models.Kategori" %>
<% ArrayList<Kategori> objKategori = (ArrayList<Kategori>) request.getAttribute("listKategori");%>

<script type="text/javascript">
    $(document).ready(function() {
        $("#addBarangForm").validate({
            rules : {
                nama_barang : {
                    required : true
                },
                harga_satuan : {
                    required : true,
                    number : true
                },
                jumlah : {
                    required : true,
                    number : true
                },
                poin : {
                    required : true,
                    number : true
                },
                deskripsi : {
                    required : true
                }
            },
            messages : {
                nama_barang : "x",
                harga_satuan : "x",
                deskripsi : "x"
            }
        });
    });
</script>

<h1>Tambah Barang</h1>
<form id="addBarangForm" action="<%=request.getContextPath()%>/barang/add" method="POST">
    <table>
        <tr>
            <td><label>Kategori</label></td>
            <td>
                <select name="kategori">
                <% for (int i = 0; i < objKategori.size(); i++) {%>
                    <option value="<%= objKategori.get(i).id%>"><%= objKategori.get(i).nama%></option>
                <% }%>
                </select>
            </td>
        </tr>
        <tr><td><label>Nama Barang</label></td><td><input type="text" name="nama_barang" /></td></tr>
        <tr><td><label>Harga Satuan</label></td><td><input type="text" name="harga_satuan" /></td></tr>
        <tr><td><label>Stock</label></td><td><input type="text" name="jumlah" /></td></tr>
        <tr><td><label>Poin</label></td><td><input type="text" name="poin" /></td></tr>
        <tr><td><label>Berat</label></td><td><input type="text" name="berat" /></td></tr>
        <tr><td><label>Deskripsi</label></td><td><textarea name="deskripsi"></textarea></td></tr>
        <tr><td></td><td><input type="submit" value="Tambah" /></td></tr>
    </table>
</form>
